package com.yao.yaoojcodesandbox.unsafe;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;

/**
 * 运行其他程序（比如写入的木马程序）
 */
public class RunFileError {
    public static void main(String[] args) throws InterruptedException, IOException {
        String userDir = System.getProperty("user.dir");//先获取用户的资源文件目录
        String filePath= userDir + File.separator + File.separator+"src/main/resources/木马程序.bat";
        Process process = Runtime.getRuntime().exec(filePath);
        process.waitFor();

        //获取编译过程中正常输出流
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(process.getInputStream()));

        String compileOutputLine;
        while((compileOutputLine = bufferedReader.readLine()) != null) { //逐行读取编译过程中出现的信息
            System.out.println(compileOutputLine);
        }
        System.out.println("执行程序成功");
    }
}
